@include('common.header')
<link rel="stylesheet" type="text/css" href="{{ asset('/css/auth.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ asset('/css/box.css') }}" />


<h1 style="margin-left:103px;margin-top:5%;" >{{ $admin->name }}</h1>
<div class="wrap">
	<div style="overflow:hidden">
	 @forelse( $controllers as $key => $controller )
			<div class="group1">
				<div class="box">
					<h2>{{ $controller->desc }}</h2>
					
				</div>
				<ul id="list">
					@forelse( $functions[$key] as $k => $func )
						<li class="roundedOne" style="margin-right:60px;">
							
							<input type="checkbox"  id="{{ $func['id'] }}" value="{{ $func['id'] }}" @if( in_array($func['id'],$auth) ) checked @else @endif  />
							
							@if( in_array($func['id'],$auth) ) 
							<label for="{{ $func['id'] }}" >
							<div style="color:red;float:left;margin-left:25px;margin-top:-2px;width:60px;">
							{{ $func['name'] }}
							</div> 
							</label>
							@else 
							<label for="{{ $func['id'] }}"  >
							<div style="float:left;margin-left:25px;margin-top:-2px;width:60px;">
							{{ $func['name'] }} 
							</div>
							</label>
							@endif
							
						</li>
					@empty
					@endforelse
				</ul>
			</div>
			@empty
			@endforelse
	</div>
       
	<div class="opera" style="margin-left:30px;text-align:center;">
		<label><input type="checkbox" value="all" id="all">全选</label>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<label><input type="checkbox" value="reverse" class="btn" id="reverse" style="margin-top:-4px">反选</label>
	</div>
	<br/>
	
	
	<div style="overflow:hidden;width:450px;margin:0 auto;">
   
		<button  style="width:200px;float:left;" class="btn btn-danger">保存</button>

		<div style="margin-left:50px;float:left;margin-bottom:200px;">
			<a href="javascript:" onclick="self.location=document.referrer;"  style="width:200px;" class="btn btn-success">
			返回
			</a>
		</div>
		
	</div>
		
		
</div>


<script type="text/javascript">
	

	function allchk(){
		// 选项总个数
		var chknum = $(".group1 :checkbox").size();
		var chk = 0;
		$(".group1 :checkbox").each(function () {
			if($(this).prop("checked")==true){
				chk++;
			}
		});
		// 选中的等于总个数
		if(chknum==chk)
		{
			// 全选按钮选中
			$("#all").prop("checked",true);
		}else{
			// 全选按钮 取消选中
			$("#all").prop("checked",false);
		}
	}
	
	// 全选
	$("#all").click(function(){
		if(this.checked){
			$(".group1 :checkbox").prop("checked", true);
		}else{
			$(".group1 :checkbox").prop("checked", false);
		}
	});
	

	//反选
	$("#reverse").click(function () {
		$(".group1 :checkbox").each(function () {
			$(this).prop("checked", !$(this).prop("checked"));
		});
		allchk();
	});

	//设置全选复选框
	$(".group1 :checkbox").click(function(){
		allchk();
	});

         
	//点击保存
	$(".btn-danger").click(function(){
		var all	 =	[];
		var key	 =	0;
		$("input[type=checkbox]:checked").each(function(){
			// 遍历 获取每个选中框的值 评论ID
			var id = $(this).val();
			if( id!= 'all' && id !='reverse' )
			{
				++key;
				all[key] = id ;
			}
		});
		if( key==0 ){
			$(".opa").html('没有选中任何权限');
			$(".opa").slideDown(1000);
			$(".opa").delay(1500).slideUp(1000);
			return false;
		}
		
		
		$.ajax({
			type:"post",
			url:"{{ url('/allocation') }}",
			data:{all:all,admin_id:{{ $admin->id }},_token:_token},
			async:true,    					
			dataType:"json",
			success:function(back){
				if( back['show_info'].indexOf("成功") > 0 )
				{
					$(".btn-danger").attr('disabled',true);
				}
				$(".opa").html(back['show_info']);
				$(".opa").slideDown(1000);
				$(".opa").delay(1500).slideUp(1000);
				
			}
		});
		
		
		
	})


</script>


@extends('common.footer')